
import axios from 'axios'

// 获取当前城市 存到locaStroage里面
export const getCurrentCity = () => {

    const city = JSON.parse(window.localStorage.getItem('liu_city'));
    // 没有发起请求
    if (!city) {

        try {

            return new Promise((resolve, reject) => {
                const myFun = async (result) => {
                    var cityName1 = result.name;
                    const { data } = await axios.get('/area/info', {
                        params: {
                            name: cityName1
                        }
                    })
                    window.localStorage.setItem('liu_city', JSON.stringify(data.body));
                    resolve(data.body)
                }
                var myCity = new window.BMapGL.LocalCity();
                myCity.get(myFun);
            })
        } catch (error) {
            return Promise.reject(error)
        }
    }

    // 有返回
    return Promise.resolve(city)


}